//
//  HAHoemAgentVC.m
//  HA
//
//  Created by sy on 2023/12/17.
//

#import "HAHoemAgentVC.h"
#import "HAHoemAgentSubVC.h"
#import "SGPagingView.h"

@interface HAHoemAgentVC ()<SGPageTitleViewDelegate,SGPageContentViewDelegate>

@property (nonatomic, strong) SGPageTitleView *pageTitleView;

@property (nonatomic, strong) SGPageContentView *pageContentView;

@end

@implementation HAHoemAgentVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.baseTLabel.text = @"代理管理";
    
    [self getsubVC];

    // Do any additional setup after loading the view.
}

-(void)getsubVC {
    NSMutableArray *titArr = [NSMutableArray array];
    NSMutableArray *vcArr = [NSMutableArray array];

    [titArr addObject:@"直属代理"];
    [titArr addObject:@"团队代理"];

    for (int i = 0; i < 2; i ++) {
        HAHoemAgentSubVC *vc = [[HAHoemAgentSubVC alloc]init];
        if (i == 0) {
            vc.source_id = @"1";
        }else if (i == 1) {
            vc.source_id = @"2";
        }
        [vcArr addObject:vc];
    }

    self.pageTitleView = [SGPageTitleView pageTitleViewWithFrame:CGRectMake(0, app_topH+44, kUIScreen_w, 44) delegate:self titleNames:titArr titleFont:[UIFont systemFontOfSize:18]];
    [self.view addSubview:self.pageTitleView];
    self.pageTitleView.isTitleGradientEffect = NO;
    self.pageTitleView.indicatorLengthStyle = SGIndicatorLengthStyleEqual;
    self.pageTitleView.isNeedBounces = NO;
    self.pageTitleView.titleColorStateNormal = [UIColor colorWithHexString:@"#666F83"];
    self.pageTitleView.titleColorStateSelected = [UIColor colorWithHexString:@"#21252A"];
    self.pageTitleView.indicatorColor = [UIColor colorWithHexString:@"#000000"];
    self.pageTitleView.indicatorHeight = 1;
    self.pageTitleView.titleTextScaling = 0;
    self.pageTitleView.isOpenTitleTextZoom = YES;

    CGFloat contentViewHeight = kUIScreen_h-app_topH-64-app_bottomH-5;
    self.pageContentView = [[SGPageContentView alloc] initWithFrame:CGRectMake(0, app_topH+44+44+5, kUIScreen_w, contentViewHeight) parentVC:self childVCs:vcArr];
    self.pageContentView.isScrollEnabled = YES;
    self.pageContentView.delegatePageContentView = self;
    [self.view addSubview:_pageContentView];

    [self.pageContentView setPageCententViewCurrentIndex:0];
    self.pageTitleView.selectedIndex = 0;

}

- (void)pageTitleView:(SGPageTitleView *)pageTitleView selectedIndex:(NSInteger)selectedIndex {
    [self.pageContentView setPageCententViewCurrentIndex:selectedIndex];
}

- (void)pageContentView:(SGPageContentView *)pageContentView progress:(CGFloat)progress originalIndex:(NSInteger)originalIndex targetIndex:(NSInteger)targetIndex {
    self.pageTitleView.resetSelectedIndex = targetIndex;
}

@end
